package com.xr.core.system.core.task;

import com.xr.core.system.mapper.ExceptionLogMapper;
import com.xr.core.system.mapper.OperationLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RemoveLogsTask {

    @Autowired
    private OperationLogMapper operationLogMapper;

    @Autowired
    private ExceptionLogMapper exceptionLogMapper;

    /**
     * 设置定时任务删除一天前的日志信息
     */
    @Async("taskExecutor")
    // 每5分钟执行一次
    @Scheduled(cron = "0 */5 * * * ?")
    public void deleteLogsFrom1DayAgo() {
        operationLogMapper.deleteDataFrom1DayAgo();
        exceptionLogMapper.deleteDataFrom1DayAgo();
        log.info("当前时间戳<{}>，开始执行定时任务<deleteLogsFrom1DayAgo>", System.currentTimeMillis());
    }

}
